package com.example.oauth2.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * oauth2资源服务器配置
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/oauth/**").permitAll()  //配置允许访问的url
            .anyRequest().authenticated()  //其它所有请求都需要鉴权认证，即需校验token
        ;

        //所有请求不做鉴权认证，注意请求头不能设置Authorization，如果设置了也会进行鉴权认证
        //http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
    }
}
